package com.zyh.scs.admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zyh.scs.admin.api.dto.TransactionPageDTO;
import com.zyh.scs.admin.api.vo.BillExcelCardVO;
import com.zyh.scs.admin.api.vo.BillExcelCashVO;
import com.zyh.scs.admin.api.vo.BillExcelEntityVO;
import com.zyh.scs.admin.api.vo.UserTransactionExcelVO;
import com.zyh.scs.admin.service.UserBillService;
import com.zyh.scs.admin.service.UserTransactionService;
import com.zyh.scs.common.core.util.R;
import com.zyh.scs.common.excel.annotation.ResponseExcel;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author hwh
 * @ClassName: 统计报表交易流水访问层$
 * @Description: $
 * @Date $
 * @Version 1.0
 */
@RestController
@AllArgsConstructor
@RequestMapping("/transaction")
@Tag(description = "transaction", name = "统计报表交易流水访问层")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class UserTransactionController {

    private final UserTransactionService userTransactionService;

    private final UserBillService userBillService;

    /**
     * 分页查询 统计报表交易流水
     *
     * @param page               分页对象
     * @param transactionPageDTO 参数列表
     * @return
     */
    @GetMapping("/page")
    @Operation(summary = "分页查询用户 统计报表交易流水", description = "分页查询统计报表交易流水")
    @PreAuthorize("@pms.hasPermission('scsx_transaction_view')")
    public R getUserPage(@ParameterObject Page page, TransactionPageDTO transactionPageDTO) {
        return R.ok(userTransactionService.getTransactionPage(page, transactionPageDTO));
    }

    /**
     * 分页查询 分页查询账单管理
     *
     * @param page      分页对象
     * @param beginTime
     * @param endTime
     * @param billType  1为交易流水  2为餐补 3为现金
     * @return
     */
    @GetMapping("/billPage")
    @Operation(summary = "分页查询账单管理", description = "分页查询账单管理")
    @PreAuthorize("@pms.hasPermission('scsx_bill_view')")
    public R getUserPage(@ParameterObject Page page, String beginTime, String endTime, Integer billType) {
        return R.ok(userBillService.getBillPage(page, beginTime, endTime, billType));
    }


    /**
     * 餐补现金查询流水
     *
     * @param page      分页对象
     * @param beginTime
     * @param endTime
     * @param billType  1为餐补 2为现金
     * @param guid
     * @return
     */
    @GetMapping("/getBillInfo")
    @Operation(summary = "餐补现金查询流水", description = "餐补现金查询流水")
    @PreAuthorize("@pms.hasPermission('scsx_bill_view')")
    public R getBillInfo(@ParameterObject Page page, @RequestParam(required = false) String rechargeStream, @RequestParam(required = false) String thirdRechargeStream, @RequestParam(required = false) String beginTime, @RequestParam(required = false) String endTime, String guid, Integer billType) {
        return R.ok(userBillService.getBillInfo(page, rechargeStream, thirdRechargeStream, beginTime, endTime, guid, billType));
    }


    /**
     * 钱包总览查看
     *
     * @param page      分页对象
     * @param beginTime
     * @param endTime
     * @param guid
     * @return
     */
    @GetMapping("/getBillAllInfo")
    @Operation(summary = "钱包总览查看", description = "钱包总览查看")
    @PreAuthorize("@pms.hasPermission('scsx_bill_view')")
    public R getBillInfo(@ParameterObject Page page, @RequestParam(required = false) String rechargeStream, @RequestParam(required = false) String thirdRechargeStream, @RequestParam(required = false) String beginTime, @RequestParam(required = false) String endTime, String guid) {
        return R.ok(userBillService.getBillAllInfo(page, rechargeStream, thirdRechargeStream, beginTime, endTime, guid));
    }

    /**
     * 总览查询流水
     *
     * @param beginTime
     * @param endTime
     * @param billType  1为餐补 2为现金 4总览
     * @param guid
     * @return
     */
    @GetMapping("/getBillInfoExcel")
    @ResponseExcel
    @Operation(summary = "餐补现金查询流水 billType  1为餐补 2为现金 4总览", description = "餐补现金查询流水 billType  1为餐补 2为现金 4总览")
    public List<BillExcelEntityVO> getBillInfoExcel(@RequestParam(required = false) String rechargeStream, @RequestParam(required = false) String thirdRechargeStream, @RequestParam(required = false) String beginTime, @RequestParam(required = false) String endTime, String guid, Integer billType) {
        return userBillService.getBillInfoExcel(rechargeStream, thirdRechargeStream, beginTime, endTime, guid, billType);
    }

    /**
     * 餐补查询流水
     *
     * @param beginTime
     * @param endTime
     * @param guid
     * @return
     */
    @GetMapping("/getCardExcel")
    @ResponseExcel
    @Operation(summary = "餐补查询流水", description = "餐补查询流水")
    public List<BillExcelCardVO> getCardExcel(@RequestParam(required = false) String rechargeStream, @RequestParam(required = false) String thirdRechargeStream, @RequestParam(required = false) String beginTime, @RequestParam(required = false) String endTime, String guid) {
        return userBillService.getCardExcel(rechargeStream, thirdRechargeStream, beginTime, endTime, guid);
    }

    /**
     * 现金查询流水
     *
     * @param beginTime
     * @param endTime
     * @param guid
     * @return
     */
    @GetMapping("/getCashExcel")
    @ResponseExcel
    @Operation(summary = "现金查询流水", description = "现金查询流水")
    public List<BillExcelCashVO> getCashExcel(@RequestParam(required = false) String rechargeStream, @RequestParam(required = false) String thirdRechargeStream, @RequestParam(required = false) String beginTime, @RequestParam(required = false) String endTime, String guid) {
        return userBillService.getCashExcel(rechargeStream, thirdRechargeStream, beginTime, endTime, guid);
    }

    /**
     * 账单管理下载账单
     */
    @GetMapping("/export")
    @Operation(summary = "账单管理下载账单", description = "账单管理下载账单")
    public R export(Long userBillId) {
        return R.ok(userBillService.getDownLoadExcel(userBillId));
    }

    /**
     * 交易流水Excel导出
     */
    @GetMapping("/getExcel")
    @ResponseExcel
    @Operation(summary = "交易流水Excel导出", description = "交易流水Excel导出")
    public List<UserTransactionExcelVO> export(TransactionPageDTO transactionPageDTO) {
        return userTransactionService.getExcel(transactionPageDTO);
    }

}
